package com.longe.controller;

import com.longe.entity.User;
import com.longe.parse.ExcelParse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Slf4j
@RestController
public class ParseController {

    @RequestMapping(value = "parse")
    public void readFromExcel(MultipartFile file) throws Exception {

        String filename = file.getOriginalFilename();
        InputStream inputStream = file.getInputStream();
        Set<String> checkFields = new HashSet<>();
        checkFields.add("name");
        List<User> list = ExcelParse.parseExcel(User.class, inputStream, filename, checkFields);

        for (User user : list) {
            System.err.println(user);
        }
    }
}
